import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Storage {

	public static int horizMapSize = 0;
	public static int vertMapSize = 0;
	public static int currentHealth = 0;
	public static int currentTurn = 0;
	
	public static void saveGame() throws IOException {
		
		currentHealth = MainFrame.currentHealth;
		horizMapSize = MainFrame.horizMapSize;
		vertMapSize = MainFrame.vertMapSize;
	        
	    File newTextFile = new File("savedGame.txt");
	    FileWriter fw = new FileWriter(newTextFile);
	    fw.write("Current Health\r\n");
	    fw.write(String.valueOf(currentHealth));
	    fw.write("\r\nHorizontal Map Index\r\n");
	    fw.write(String.valueOf(horizMapSize));
	    fw.write("\r\nVertical Map Index\r\n");
	    fw.write(String.valueOf(vertMapSize));
	    fw.write("\r\n");
	    fw.close();
	    }
	
	public static int loadHealth(int loadHealth) throws IOException{
		
		File file = new File("savedGame.txt");//Creates a FileReader Object	
	    FileReader fr = new FileReader(file); 
	    
	    char [] return0 = new char[16];
	    fr.read(return0); // reads the content to the array
	    char [] a = new char[2];
	    fr.read(a); // reads the content to the array  
	    loadHealth = Integer.parseInt(String.valueOf(a));
	    System.out.println("Loaded Health = " + loadHealth);
	    return loadHealth;
	    
	}
	
	public static int loadMapIndex1(int loadMapIndex1) throws IOException{
		
		File file = new File("savedGame.txt");//Creates a FileReader Object	
	    FileReader fr = new FileReader(file); 
	    
	    char [] return0 = new char[16];
	    fr.read(return0); // reads the content to the array	    
	    char [] b = new char[2];
	    fr.read(b); // reads the content to the array	    
	    char [] return1 = new char[24];
	    fr.read(return1); // reads the content to the array
	    char [] a = new char[2];
	    fr.read(a); // reads the content to the array 
	    loadMapIndex1 = Integer.parseInt(String.valueOf(a));
	    System.out.println("Loaded Map Index 1 = " + loadMapIndex1);
	    return loadMapIndex1;  
	}
	
	public static int loadMapIndex2(int loadMapIndex2) throws IOException{
		
		File file = new File("savedGame.txt");//Creates a FileReader Object	
	    FileReader fr = new FileReader(file); 
	    
	    char [] return0 = new char[16];
	    fr.read(return0); // reads the content to the array	    
	    char [] b = new char[2];
	    fr.read(b); // reads the content to the array	    
	    char [] return1 = new char[24];
	    fr.read(return1); // reads the content to the array
	    char [] c = new char[2];
	    fr.read(c); // reads the content to the array	    
	    char [] return2 = new char[22];
	    fr.read(return2); // reads the content to the array 	    
	    char [] a = new char[2];
	    fr.read(a); // reads the content to the array   
	    loadMapIndex2 = Integer.parseInt(String.valueOf(a));
	    System.out.println("Loaded Map Index 2 = " + loadMapIndex2);
	    return loadMapIndex2;  
	}
	    
}